/**
 * cloudID通过处理转化成https链接
 * @param {*} cloudId 云储存文件id
 * @param {*} styleName 云储存图片处理样式名称（可选）
 * @returns
 */
const cloudId2Http = (cloudId: string, styleName?: string) => {
  if (!cloudId) return '请传入cloudID'
  const strs = cloudId.split('.')
  const strs_2 = strs[1]
  const strs_3 = strs_2.split('/')
  const envId = strs_3[0]
  const https_prefix = `https://${envId}.tcb.qcloud.la/`
  let filePath = ''
  for (let i = 1; i < strs_3.length; i++) {
    if (i === strs_3.length - 1) {
      const fileName = strs_3[i] + '.' + strs[strs.length - 1]
      filePath += fileName
    } else {
      filePath += strs_3[i] + '/'
    }
  }
  let httpsUrl = https_prefix + filePath
  if (styleName) httpsUrl += '/' + styleName
  return httpsUrl
}

export { cloudId2Http }
